/**
 * 建课第一步
 */
var _debug=false;
var $currentTeacherDto = [];// 当前教师Dto
var $firstStepRecordCourse=[];//记录第一步课程信息
//先修课程百度编辑器
var prerequisiteEditor=newEditor("prerequisite","100%",50);
// 页面加载完毕后调用
$(function() {

	init();
	
	// 置顶
	backToTop();
	// 先修课程添加监听
	prerequisiteEditor.addListener("blur", function(type, event) {
		titPWarn('#tit-p-prerequisite', getTxt(prerequisiteEditor).trim());
		updateCourse("courseAcademicPrepare",getTxt(prerequisiteEditor).trim() == "" ? "": plainTxt(prerequisiteEditor));
	});

	// 去除 面对面学时数 和 视频课时数 的小数点
	$("#hours_video_lectures,#face_to_face_lectures").bind("keyup",function() {

				var hours_video_lectures = $('#hours_video_lectures').val();
				var face_to_face_lectures = $('#face_to_face_lectures').val();
				$('#hours_video_lectures').val(hours_video_lectures.replace(/\D/g, ''));
				$('#face_to_face_lectures').val(face_to_face_lectures.replace(/\D/g, ''));
			});

	// 通过bind()绑定失去焦点事件
	$("#hours_video_lectures,#face_to_face_lectures").bind("blur", function() {
		addHourseFaceLectures();
	});
	$("#course_title").bind("keyup", function() {
		courseTitelLength();
	});
	$("#course_title").bind("blur", function() {
		$(".coursetitle-input").css("border", "");
		titPWarn('#tit-p-coursetitle', $('#course_title').val());
	});
	$("#schoolName").bind("blur", function() {
		titPWarn('#firststep_institutuion', $('#schoolName').val().trim());
	});
	$("#credits_score").bind("blur", function() {
		warnCreditsScore('#tit-p-credits', $('#credits_score').val());
	});

});

// 页面初始化后调用的函数
function init() {
	onblurUpdateCourse();// 文本框失去焦点的事件
	selectTblCourse();// 查询课程信息
	selectCourseInstructor();// 查询教师团队信息
	searchPromoVideo();// 查询片花
	addCourseInsetuctor();// 添加教师团队绑定
	showWarn();// 页面打开时加载的警告 时勾还是感叹号
	nextAction();// 下一步方法绑定

	// 图片弹窗绑定
	_loadImageShow();


};

/** 各种事件的绑定与验证 */

// 页面打开时加载的警告 时勾还是感叹号
function showWarn() {

	titPWarn('#tit-p-coursetitle', $('#course_title').val());
	titPWarn('#tit-p-category', $("#course_Category").val());
	titPWarn('#firststep_institutuion', $('#schoolName').val());
	warnCreditsScore('#tit-p-credits', $('#credits_score').val());
	warnImg('#tit-p-courseimg', $(".singlePhoto>img").attr("src"));
	warnImg('#tit-p-pianhua', $("#PromoVideo>img").attr("src"));
}

// 判断各个文本框是否有值 显示对号还是感叹号
function titPWarn(id, str) {
	warnSymbol(id, str);
}

function titPwarnBool(id, bool) {
	warnboolSymbol(id, bool);
}

// 点击 Add Instructor 增加一个教学团队
function addCourseInsetuctor() {
	$("#addCourseInstructor-addfont").click(function() {
		addInstructor(1);
		searchInstructorFull(httpInstructorEN, httpInstructorZH);

		// 初始化上传组件
		loadAspUpload();
	});
}

// 各个文本框失去焦点的事件 -- 修改课程
function onblurUpdateCourse() {
	$("#course_title").bind("blur", function() {
		var val = $("#course_title").val();
		if (val.trim() == "" || val.trim() == null) {
			return false;
		}

		// 修改头部的课程名称
		$("#public_title_name").text(val);
		$("#header_first_title").text(val);
		updateCourse("name", val);
	});
	$("#schoolName").bind("blur", function() {
		updateCourse("schoolName", $("#schoolName").val().trim());
	});
	$("#credits_score").bind("blur", function() {
		updateCourse("credit", $("#credits_score").val());
	});
	$("#hours_video_lectures").bind("blur", function() {
		updateCourse("onlineCoursePeriod", $("#hours_video_lectures").val());

		// 将总学时添加到数据库
		var total_class_hours = $("#total_class_hours span").html();
		if (!isNaN(total_class_hours)) {
			updateCourse("period", total_class_hours);
		}
	});
	$("#face_to_face_lectures").bind("blur", function() {
		updateCourse("meetCoursePeriod", $("#face_to_face_lectures").val());

		// 将总学时添加到数据库
		var total_class_hours = $("#total_class_hours span").html();
		if (!isNaN(total_class_hours)) {
			updateCourse("period", total_class_hours);
		}
	});
	// 课程类别添加change()事件
	$("#course_Category").on("change", function() {
		updateCourse("courseCategory", $("#course_Category").val());
		titPWarn('#tit-p-category', $("#course_Category").val());
		judgeCateGory();
	});
}

/** 获取与修改课程信息  */

//根据课程Id 查询所有的课程
function selectTblCourse() {
	
			$.ajax({
				type : "post",
				url : basePath + "/course/firstStep/queryCourseInfo",
				data : {
					"courseId" : $("#courseId").val(),
				},
				async : false,//同步
				dataType : 'json',
				beforeSend : function() {
				},
				success : function(response) {
					if (response.success && response.result !=null) {						

						$("#course_title").val(response.result.name);// Course Title
						$("#courseImageShow").attr('src', response.result.img); // Course
						$("#schoolName").val(response.result.schoolName);// Institution
						$("#credits_score").val(response.result.credit);// Credits
						$("#hours_video_lectures").val(response.result.onlineCoursePeriod);// Class Hours
						$("#face_to_face_lectures").val(response.result.meetCoursePeriod);// Class Hours of	
						$("#course_Category").val(response.result.courseCategory);// Category
						judgeCateGory();
						loadEditorText(prerequisiteEditor,response.result.courseAcademicPrepare == null ? "": response.result.courseAcademicPrepare);// prerequisite
						$("#linkCourseId").val(response.result.linkCourseId);
						if (response.result.img != null && response.result.img != "") {
							$(".singlePhoto").css("border","1px solid #ccc");
							$(".singlePhoto>img").attr("src", response.result.img);
							$(".singlePhoto>img").addClass("layerImageShow");
							$(".singlePhoto>img").show();

							$("#_uploadCourseImageDiv").removeClass("uploadBtn_courseTitle");
							$("#_uploadCourseImageDiv").addClass("setedit_editico");
							$("#course_Image").val("test");

							
						}
						
						titPWarn('#tit-p-prerequisite',response.result.courseAcademicPrepare);

						addHourseFaceLectures();// 计算 面对面课时数 和 视频课时数 的值
						courseTitelLength();// 记录 课程名称的长度
						
						//记录第一步课程信息
						$firstStepRecordCourse=response.result;
					}
				},
				error : function(data) {

				},
				complete : function(response) {
				}
			});
}

// 修改课程信息
function updateCourse(name, value){
	
	//验证数据是否改变
	//consoleTestInfo("name:"+name+"*****"+"Rvalue:"+$firstStepRecordCourse[name]+"====="+value);
	if($firstStepRecordCourse[name] !=value){
		
		var dataParm = {
			"courseId" : $("#courseId").val()
		};
		dataParm[name] = value;
		$.ajax({
			type : "post",
			url : basePath + "/course/firstStep/updateCourseInfo",
			data : dataParm,
			cache : false,
			dataType : 'json',
			beforeSend : function() {
			},
			success : function(data) {
				//更新课程记录信息
				$firstStepRecordCourse[name]=value;
			},
			error : function(data) {
			},
			complete : function() {
			}
		});
	}
}

/** 教学团队  */

// 根据教师id删除教师信息
function delInstructior(index) {

	var teacherId = $("#teacherId-" + index + "").val();
	layer.confirm(zLocale.public_message, {
		title : ' ',
		icon : 0,
		shade : .6,
		skin : 'layui-layer-zhs',
		btn : [ zLocale.public_confim, zLocale.public_cancel ], // 按钮
	}, function(closeIndex) {

		// 如果tid存在走数据库操作，不存在从页面移除
		if (teacherId != "" && teacherId != undefined && teacherId != null) {
			
					$.ajax({
						type : "post",
						url : basePath + "/course/firstStep/delCourseSpeaker",
						data : {
							"id" : teacherId,
						},
						dataType : 'json',
						beforeSend : function() {
						},
						success : function(data) {
							if (data) {
								layer.close(closeIndex);// 关闭弹窗
								$(".information-divTitle").find("#information-div-" + index + "").remove();
								searchInstructorFull(httpInstructorEN,httpInstructorZH);
							}
						},
						error : function(data) {
						},
						complete : function() {
						}
					});
		} else {
			layer.close(closeIndex);// 关闭弹窗
			$(".information-divTitle").find("#information-div-" + index + "").remove();
			searchInstructorFull(httpInstructorEN, httpInstructorZH);
		}
	}, function() {
	});

}



// 查询所有的教师团队
function selectCourseInstructor() {

	$.ajax({
		type : "post",
		url : basePath + "/course/firstStep/courseSpeakearList",
		data : {
			"courseId" : $("#courseId").val(),
		},
		dataType : 'json',
		async : false,//同步
		beforeSend : function() {
		},
		success : function(response) {
			// consoleTestInfo(response);
			// 判断是否有教学团队 存在的话则创建教学团队的div,如果不存在教学团队 则默认创建一个
			if (response != null) {
				if (response.result !=null && response.result.length > 0) {
					var typeNum = 0;// 课程主讲人个数
					for (var i = 0; i < response.result.length; i++) {
						if (response.result[i].userType == 2) {
							typeNum++;
						}
						addInstructor("", response.result[i], Constants._layerShow);
					}
					if (typeNum <= 0) {
						addInstructor(2);
					}

				} else {
					addInstructor(2);
				}
				initUploader();
				searchInstructorFull(httpInstructorEN, httpInstructorZH);
			}
		},
		error : function(data) {
		},
		complete : function() {
		}
	});
}

// 教师团队 增加或者修改 （如果 value 存在则做增加 否则则做修改）
// value 是文本框值  floorIndex 是下标
function addUpdateCourseInstructor(floorIndex, value) {
	if (value != null && strTrim(value) != "") {

		// 判断教师信息是否改变
		if ($.inArray(value, $currentTeacherDto) == -1) {

			var teacherId = $("#teacherId-" + floorIndex + "").val();
			var imgSrcValue = $(
					"#firstStep_courseInstructorImg-" + floorIndex + "").attr(
					"src");
			var courseId = $("#courseId").val();
			var username = $("#username-" + floorIndex + "").val();
			var jobstatus = $("#jobstatus-" + floorIndex + "").val();
			var decription = $("#decription-" + floorIndex + "").val();
			var userType = $("#userType-" + floorIndex + "").val();

			// consoleTestInfo(username+"===="+jobstatus+"======"+decription+"======="+imgSrcValue);
			// consoleTestInfo("tid:"+teacherId+"====="+value);

			// 判断tid是否存在
			if (teacherId != "" && teacherId != null) {
				// 则做修改
				
						$.ajax({
							type : "post",
							url : basePath+ "/course/firstStep/updateSpeakerCourse",
							data : {
								"courseId" : courseId,
								"id" : teacherId,
								"username" : username,
								"jobstatus" : jobstatus,
								"decription" : decription,
								"userType" : userType,
								"img" : imgSrcValue,
							},
							dataType : 'json',
							beforeSend : function() {
							},
							success : function(data) {
								searchInstructorFull(httpInstructorEN,
										httpInstructorZH);
								// 重新记录
								$currentTeacherDto = [];
								record_CurrentTeacher(floorIndex, value);
							},
							error : function(data) {
							},
							complete : function() {
							}
						});
			} else {
				// 则做增加
				
						$.ajax({
							type : "post",
							url : basePath
									+ "/course/firstStep/saveSpeakerCourse",
							data : {
								"courseId" : courseId,
								"username" : username,
								"jobstatus" : jobstatus,
								"decription" : decription,
								"userType" : userType,
								"img" : imgSrcValue,
							},
							dataType : 'json',
							async : false,
							beforeSend : function() {
							},
							success : function(response) {
								if (response != null) {
									// consoleTestInfo("courseId:"+response.result.courseId);
									$("#teacherId-" + floorIndex + "").val(
											response.result.id);
									$("#ahref-" + floorIndex + "").attr(
											"href",
											"javascript:delInstructior("
													+ floorIndex + ","
													+ response.result.id + ")");
								}
								searchInstructorFull(httpInstructorEN,
										httpInstructorZH);
								// 重新记录
								$currentTeacherDto = [];
								record_CurrentTeacher(floorIndex, value);
							},
							error : function(data) {
							},
							complete : function(response) {
							}
						});
			}
		}
	}
}
// 获取焦点记录当前的教师团队数据
function record_CurrentTeacher(index, value) {

	if (value != null && strTrim(value) != "") {
		var username = $("#username-" + index + "").val();
		var jobstatus = $("#jobstatus-" + index + "").val();
		var decription = $("#decription-" + index + "").val();

		// consoleTestInfo(decription+"======");
		if (username!=null && username.length > 0 && strTrim(username) != ""
				&& $.inArray("username:" + username, $currentTeacherDto) == -1) {
			$currentTeacherDto.push("username:" + username);
		}
		if (jobstatus!=null && jobstatus.length > 0
				&& strTrim(jobstatus) != ""
				&& $.inArray("jobstatus:" + jobstatus, $currentTeacherDto) == -1) {
			$currentTeacherDto.push("jobstatus:" + jobstatus);
		}
		if (decription!=null && decription.length > 0
				&& strTrim(decription) != ""
				&& $.inArray("decription:" + decription, $currentTeacherDto) == -1) {
			$currentTeacherDto.push("decription:" + decription);
		}
	}
	// consoleTestInfo($currentTeacherDto);
}

//判断所有的教师团队内容是否填写完整
function searchInstructorFull(strImgEN, strImgZH) {
	var bool1 = false;
	var bool2 = false;
	var bool3 = false;

	// 判断所有的文本框是否为空
	$(".information-divTitle").find("input[type=text]").each(
			function() {
				if ($(this).attr("value").trim() != null
						&& $(this).attr("value").trim() != "") {
					bool1 = true;
				} else {
					bool1 = false;
					titPwarnBool("#tit-p-courseinstructor", bool1);
					return false;
				}
			});

	// 判断所有的头像是否为空
	$(".information-divTitle").find("img").each(function() {
		var src = $(this).attr("src").toLocaleLowerCase();
		if (src != null && src != "") {
			if (src == strImgEN || src == strImgZH) {
				bool2 = false;
				titPwarnBool("#tit-p-courseinstructor", bool2);
				return false;
			}
			bool2 = true;
		} else {
			bool2 = false;
			titPwarnBool("#tit-p-courseinstructor", bool2);
			return false;
		}
	});

	// 判断所有的文本域是否为空
	$(".information-divTitle").find("textarea").each(
			function() {
				if ($(this).attr("value").trim() != null
						&& $(this).attr("value").trim() != "") {
					bool3 = true;
				} else {
					bool3 = false;
					titPwarnBool("#tit-p-courseinstructor", bool3);
					return false;
				}
			});

	if (bool1 == true && bool2 == true && bool3 == true) {
		titPwarnBool("#tit-p-courseinstructor", true);
	}
}


//增加教学团队 type 2 是课程主讲人，1 是助教
function addInstructor(type, data, className) {
	
	if(className ==null || className ==undefined){
		className="";
	}
	
	// 获取最后一个教师的下标，拼接字符串、添加教师
	var lastDiv = $(".information-divTitle").find(".information-div").last();
	var courseSpeaker = $("#fristStep-courseSpeakerShow");// 主讲人
	var courseAssistant = $("#fristStep-courseAssistantShow");// 助教
	var ids = new Date().getTime();
	// 默认样式
	var btnClass = "uploadBtn_courseInstructor";
	var displayValue = "none";
	var src = "";
	var username = "";
	var jobstatus = "";
	var decription = "";
	var teacheid = "";
	var border="";
	if (data != null && type == "") {
		type = data.userType;
		username = data.username;
		jobstatus = data.jobstatus;
		decription = data.decription;
		teacheid = data.id;
		ids = data.id;
		if (data.img != "" && data.img != null) {
			btnClass = "setedit_editico";
			displayValue = "block";
			src = data.img;
			border="border:1px solid #ccc;";
		}
	}
	var div = '<div class="information-div" data-type="' + type
			+ '" id="information-div-' + ids + '" data-index="' + ids + '"> ';
	if (type == 1){
		div += '<a id="ahref-' + ids + '" href="#"> ';
		div += '<span class="informationdelete-ico"></span>';
		div += '</a>';
	}
	div += '<div class="information-l fl">';
	div += '<div class="manyPhoto" style="'+border+'">';
	div += '<img class="' + className + '" style="display:' + displayValue
			+ ';"  name="courseInstructor" id="firstStep_courseInstructorImg-'
			+ ids + '" src="' + src + '" />';
	div += '<div class="' + btnClass + '" id="courseInstructorImgsDiv-' + ids
			+ '">';
	div += '<span  id="aspUploadImags-' + ids + '"></span>';
	div += '</div>';
	div += '</div>';
	div += '</div>';
	div += '<div class="information-r fl">';
	div += '<ul>';
	div += '<li style="display:none"><input name="id" id="teacherId-' + ids
			+ '" value="' + teacheid + '"  type="text"></li>';
	div += '<li><input style= "overflow:hidden; resize:none;" name="username"  maxlength="30"  id="username-'
			+ ids
			+ '" value="'
			+ username
			+ '" class="fullname getFocus"  type="text"/></li>';
	div += '<li><input style= "overflow:hidden; resize:none;" name="jobstatus" maxlength="30"  id="jobstatus-'
			+ ids
			+ '" value="'
			+ jobstatus
			+ '" class="title getFocus"  type="text"/></li>';
	div += '<li><textarea onkeyup="ResizeTextarea('
			+ ids
			+ ')" style= "overflow:hidden; resize:none;" name="decription" id="decription-'
			+ ids
			+ '" value= "" class="personalprofile getFocus" cols="" rows="">'
			+ decription + '</textarea></li>';
	div += '<li style="display:none"><input name="userType" id="userType-'
			+ ids + '"  value="' + type + '" type="text"></li>';
	div += '</ul>';
	div += '</div>';
	div += '</div>';

	if (type == 1) {
		courseAssistant.append(div);
	} else if (type == 2) {
		courseSpeaker.append(div);
	}
	// 添加placeholder属性
	$("#ahref-" + ids + "").attr("href","javascript:delInstructior(" + ids + ")");
	$("#username-" + ids + "").attr("placeholder",zLocale.firststep_jiangshimingcheng);
	$("#jobstatus-" + ids + "").attr("placeholder",zLocale.firststep_jiangshizhiwei);
	$("#decription-" + ids + "").attr("placeholder",zLocale.firststep_jiangshijianjie);

	// 添加绑定事件
	$("#username-" + ids + ",#jobstatus-" + ids + ",#decription-" + ids).on("blur", function() {
				var checkValue = "";
				if ($(this).val()!=null && strTrim($(this).val()).length > 0) {
					checkValue = $(this).attr("name") + ":" + $(this).val();
				}
				addUpdateCourseInstructor(ids, checkValue);
	});
	$("#username-" + ids + ",#jobstatus-" + ids + ",#decription-" + ids).on("focus", function() {
				$currentTeacherDto = [];
				record_CurrentTeacher(ids, $(this).val());
	});
	// Textarea 高度自适应
	ResizeTextarea(ids);
}




/** 课程片花  */

// 查询片花
function searchPromoVideo() {
	var value = $("#linkCourseId").val();
	if (value != "" && value != null) {
		$.ajax({
			type : "post",
			url : basePath + "/course/firstStep/searchCourseClipse",
			data : {
				"clipsId" : value,
			},
			dataType : 'json',
			async : false,
			beforeSend : function() {
			},
			success : function(response) {

				if (response.result !=null && response.result.videoId != null && response.result.clipsId != null) {
					IsExitsPromoVideoImg(response.result);
				}
			},
			error : function(data) {
			},
			complete : function() {

			}
		});
	}
}

// 判断片花封面是否存在
function IsExitsPromoVideoImg(result) {

	// 判断是否有课程封面
	// 如果有直接展示，没有从接口中获取。
	// 接口中如果有，更新图片
	if (result.videoImage == "" || result.videoImage == null) {
		PromoVideoImg(result);
	} else {
		loadPromoVideoImg(result);
	}
};

// 加载视频片花样式
function loadPromoVideoImg(result) {

	// 修改上传样式
	$("#uploadBtn_promoVideo-Div").removeClass("uploadBtn_promoVideo");
	$("#uploadBtn_promoVideo-Div").addClass("setedit_editico");

	// 视频转码提示
	var img = result.videoImage;
	if (result.videoImage == "" || result.videoImage == null) {
		img = promoVideoImg;
		$("#uploadPromoVideo-div #PromoVideo>.message").show();
		$("#uploadPromoVideo-div #PromoVideo>.imageIcon").hide();
	} else {
		$("#uploadPromoVideo-div #PromoVideo>.message").hide();
		$("#uploadPromoVideo-div #PromoVideo>.imageIcon").show();
	}

	$("#linkCourseId").val(result.clipsId);
	$("#videoSrc").val(result.videoId);
	$("#videoSrc").attr("src", result.videoImage);

	// 加载图片
	$("#uploadPromoVideo-div #PromoVideo>img").attr("src", img);
	$("#uploadPromoVideo-div #PromoVideo>img").show();
	warnImg('#tit-p-pianhua', $("#PromoVideo>img").attr("src"));//重新验证封面是否完整
};
// 查询视频片花封面 视频id
function PromoVideoImg(result) {
	$.ajax({
		type : "post",
		url : basePath + "/course/firstStep/updatePromoVideoImg",
		data : {
			"courseId" : $("#courseId").val(),
			"ids" : result.videoId,
			"videoId" : result.videoId,
			"clipsId" : result.clipsId
		},
		dataType : 'json',
		beforeSend : function() {
		},
		success : function(data) {
			if (data.success && data.result !=null){

				loadPromoVideoImg(data.result);
			}
		},
		error : function(data) {
		},
		complete : function() {
		}
	});
}

//上传片花
function uploadClips(ids, filePath) {
	var value = $("#linkCourseId").val();
	if (value >0) {// 修改
		$.ajax({
			type : "post",
			url : basePath + "/course/firstStep/updateClips",
			data : {
				"clipsId" : $("#linkCourseId").val(),
				"videoId" : ids,
				"videoPath" : filePath,
				"videoImage" : ""
			},
			dataType : 'json',
			beforeSend : function() {
			},
			success : function(data) {
				if (data.success && data.result!=null) {
					if (data.result.videoImage == "" || data.result.videoImage == null) {
						$("#PromoVideo-id").attr("src", promoVideoImg);
					} else {
						$("#PromoVideo-id").attr("src", data.result.videoImage);
					}
					$("#PromoVideo").addClass("uploadPromo-div PromoVideo");
					videoInit();
				}
			},
			error : function(data) {
			},
			complete : function() {
			}
		});
	} else {// 走上传
		
			$.ajax({
				type : "post",
				url : basePath + "/course/firstStep/saveClips",
				data : {
					"courseId" : $("#courseId").val(),
					"videoPath" : filePath,
					"videoImage" : ""
				},
				dataType : 'json',
				beforeSend : function() {
				},
				success : function(data) {
					if (data.success) {
						if (data.result != null && data.result != "") {
							$("#linkCourseId").val(data.result.clipsId);
							if (data.result.videoImage == ""
									|| data.result.videoImage == null) {
								$("#PromoVideo-id").attr("src",promoVideoImg);
							} else {
								$("#PromoVideo-id").attr("src",data.result.videoImage);
							}
							$("#PromoVideo").addClass("uploadPromo-div PromoVideo");
							videoInit();
						}
					}
				},
				error : function(data) {
				},
				complete : function() {
				}
			});
	}
}


/** 数据校验 */

function nextAction() {
	$(".btn-Style").click(function() {
		var courseId = $("#courseId").val();
		location = "secondStep?courseId=" + courseId;
	});
}

//记录页面的数据
function firstStepRecordInfo(){
	$courseTitle=$("#course_title").val();
	$courseInstitution=$("#schoolName").val();
	$courseCredits=$("#credits_score").val();
	$courseVideoLectures=$("#hours_video_lectures").val();
	$courseFaceLectures=$("#face_to_face_lectures").val();
			$coursePrerequisites=response.result.courseAcademicPrepare ;
			//console.info($coursePrerequisites);

}

// 记录 课程名称的长度
function courseTitelLength() {
	var course_title = $("#course_title").val();
	var len;// 记录长度
	if (course_title!=null && course_title.length > 120) {
		$("#course_title").val(course_title.substr(0, 120));
		len = 0;
	} else {
		len = 120 - course_title.length;
	}
	$("#course_title_maxSum").html(len);
}

// 因为图片过来的有默认的 所以 应该再传过来一个图片默认的
function warnImg(id, str) {
	
	var html = '<span class="hintico"></span>';
	var html = "";
	if (str == "" || str == "null" || str == null) {
		html = '<span class="hintico"></span>';
		var htm = html.substr(13, 7);
	} else {
		html = '<span class="rightico"></span>';
		var htm = html.substr(13, 8);
	}
	var pre = $(id).prev().attr("class");
	$(id).prev().remove();
	$(id).before(html);

	if (pre != undefined && pre != htm) {
		var value = $("#courseId").val();
		if (value != '' && value != undefined && value != null) {
			$.ajax({
				type : "post",
				url : basePath + "/course/cleanTreeRedis",
				data : {
					"courseId" : value
				},
				dataType : 'json',
				success : function(data) {

				}
			});
		}

	}
}

// 如果学分是0 或者 0.0 还是警告的提示框
function warnCreditsScore(id, str) {
	var html = "";
	if (str == "" || str == "null" || str == null) {
		html = '<span class="hintico"></span>';
		var htm = html.substr(13, 7);
	} else {
		if (str == "0.0" || str == "0" || str == "00" || str == "000"
				|| str == "0000") {
			html = '<span class="hintico"></span>';
			var htm = html.substr(13, 7);
		} else {
			html = '<span class="rightico"></span>';
			var htm = html.substr(13, 8);
		}
	}
	var pre = $(id).prev().attr("class");
	$(id).prev().remove();
	$(id).before(html);

	if (pre != undefined && pre != htm) {
		var value = $("#courseId").val();
		if (value != '' && value != undefined && value != null) {
			$.ajax({
				type : "post",
				url : basePath + "/course/cleanTreeRedis",
				data : {
					"courseId" : value
				},
				dataType : 'json',
				success : function(data) {

				}
			})
		}

	}
}



// 计算 面对面课时数 和 视频课时数 的值
function addHourseFaceLectures() {
	var bool = false;
	var hours_video_lectures = $('#hours_video_lectures').val();
	var face_to_face_lectures = $('#face_to_face_lectures').val();
	var total_class_hours = Number(hours_video_lectures)
			+ Number(face_to_face_lectures);
	if (hours_video_lectures != "" && hours_video_lectures != null
			&& face_to_face_lectures != "" && face_to_face_lectures != null) {
		if (hours_video_lectures == "00" || hours_video_lectures == "0"
				|| face_to_face_lectures == "00"
				|| face_to_face_lectures == "0") {
			bool = false;
		} else {
			bool = true;
		}

	}
	$("#total_class_hours").html(zLocale.firstsetp_zongxueshi + ":<span class='totalhours-span'>"+ total_class_hours + "</span>");
	$("#totalhours-span-id").attr("class", "totalhours-span");
	titPwarnBool(("#tit-p-keshishu"), bool);

}

// Textarea 高度自适应
// 最小高度
var minRows = 2;
// 最大高度，超过则出现滚动条
var maxRows = 250;
function ResizeTextarea(index) {
	var t = document.getElementById('decription-' + index + '');
	if (t.scrollTop == 0)
		t.scrollTop = 1;
	while (t.scrollTop == 0) {
		if (t.rows > minRows)
			t.rows--;
		else
			break;
		t.scrollTop = 1;
		if (t.rows < maxRows)
			t.style.overflowY = "hidden";
		if (t.scrollTop > 0) {
			t.rows++;
			break;
		}
	}
	while (t.scrollTop > 0) {
		if (t.rows < maxRows) {
			t.rows++;
			if (t.scrollTop == 0)
				t.scrollTop = 1;
		} else {
			t.style.overflowY = "auto";
			break;
		}
	}
	if ($("#decription-" + index + "").val() == ""
			|| $("#decription-" + index + "").val() == null) {
		$("#decription-" + index + "").attr("rows", "");
	} 
}


// 当课程类别有值时，隐藏请选择课程类别
function judgeCateGory() {
	if ($("#course_Category").val() != null
			&& $("#course_Category").val() != ""
			&& $("#course_Category").val() != "null") {
		$("#course_Category_choose").remove();
	}
}

